import { Message } from 'element-ui'
'use strict'

import cryptoJs from 'crypto-js'
let keyOne = '14725800'
// 加密函數
function jiami (word) {
  const KeyHex = cryptoJs.enc.Utf8.parse(keyOne);
  const encrypted = cryptoJs.DES.encrypt(word, KeyHex, {
    mode: cryptoJs.mode.ECB,
    padding: cryptoJs.pad.Pkcs7
  });

  let hexstr = encrypted.toString();
  return hexstr;
}
// 解密函數
function jiemi (word) {
  console.log('传入的密文：', word)
  const KeyHex = cryptoJs.enc.Utf8.parse(keyOne);
  const decrypted = cryptoJs.DES.decrypt(word, KeyHex, {
    mode: cryptoJs.mode.ECB,
    padding: cryptoJs.pad.Pkcs7
  });
  return decrypted.toString(cryptoJs.enc.Utf8);
}
function tips (res, message) {
  if (res) {
    Message({
      message: message || '操作成功',
      type: 'success',
      duration: 1000
    })
  } else {
    Message({
      message: message || '操作失败',
      type: 'error',
      duration: 1000
    })
  }
}
export default {
  jiami: jiami,
  jiemi: jiemi,
  tips: tips
}
